package com.shaonianyou.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;

/**
 * 我的下线
 *
 * @author Empty
 */
@Controller
@RequestMapping("/recruitment")
public class RecruitmentController extends BaseController {

    /**
     * 下级统计
     *
     * @param custId
     * @return
     */
    @RequestMapping("/queryRecommendInfo")
    @ResponseBody
    public Map<String, Object> queryRecommendInfo(String custId, HttpServletRequest request) {
        Map<String, Object> param = Maps.newHashMap();
        if (!StringUtils.isBlank(custId)) {
            param.put("custId", custId);
        } else {
            param.put("custId", request.getSession().getAttribute("custId"));
        }

        return doPost("/recommend", param);
    }

    /**
     * 下级统计
     *
     * @param custId
     * @return
     */
    @RequestMapping("/recommendCount")
    @ResponseBody
    public Map<String, Object> recommendCount(String custId, HttpServletRequest request) {
        Map<String, Object> param = Maps.newHashMap();
        param.put("custId", request.getSession().getAttribute("custId"));
        return doPost("/recommendCount", param);
    }


    /**
     * 合作会员查询
     *
     * @param custId
     * @param request
     * @return
     */
    @RequestMapping("/coolRecommend/{pageIndex}")
    @ResponseBody
    public Map<String, Object> coolRecommend(HttpServletRequest request, @PathVariable String pageIndex) {
        Map<String, Object> param = Maps.newHashMap();
        param.put("custId", request.getSession().getAttribute("custId"));
        param.put("pageIndex", pageIndex);
        return doPost("/coolRecommend", param);
    }

    /**
     * 查询下线业绩
     *
     * @param request
     * @param custId
     * @param pageIndex
     * @return
     */
    @RequestMapping("/findIntegralBysubcustId/{pageIndex}")
    @ResponseBody
    public Map<String, Object> findIntegralBysubcustId(HttpServletRequest request, String subcustId,
                                                       @PathVariable String pageIndex) {
        Map<String, Object> param = Maps.newHashMap();
        param.put("pageIndex", pageIndex);
        param.put("subcustId", subcustId);
        param.put("custId", request.getSession().getAttribute("custId"));
        Map<String, Object> result = doPost("/findIntegralBysubcustId", param);
        return result;
    }
}
